package com.it.hanzhongtravelv1.controller;

import com.it.hanzhongtravelv1.dto.CulturalActivityDTO;
import com.it.hanzhongtravelv1.entity.CulturalActivity;
import com.it.hanzhongtravelv1.service.CulturalActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/cultural-activities")
@CrossOrigin(origins = {"http://localhost:5173", "http://localhost:8080"})
public class CulturalActivityController {

    @Autowired
    private CulturalActivityService culturalActivityService;

    @GetMapping
    public List<CulturalActivityDTO> getAllActivities() {
        return culturalActivityService.getAllActivities();
    }

    @PostMapping
    public ResponseEntity<CulturalActivityDTO> createActivity(@RequestBody CulturalActivity activity) {
        CulturalActivityDTO newActivity = culturalActivityService.saveActivity(activity);
        return ResponseEntity.ok(newActivity);
    }

    @PutMapping("/{id}")
    public ResponseEntity<CulturalActivityDTO> updateActivity(@PathVariable Long id, @RequestBody CulturalActivity activity) {
        activity.setId(id);
        CulturalActivityDTO updatedActivity = culturalActivityService.saveActivity(activity);
        return ResponseEntity.ok(updatedActivity);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Void> deleteActivity(@PathVariable Long id) {
        culturalActivityService.deleteActivity(id);
        return ResponseEntity.noContent().build();
    }
} 